|
|
|
|
|
|
|
Listing 15.7. Adding the WHERE clause to the UPDATE statement. |
|
|
|
|
|
|
|
|
//
// sqlvb06.sqv - testing the UPDATE ... SET statement
//
// create a database
dbMake sqlvb06.mdb;
// create a table
CREATE TABLE EmpTable
(EmpID TEXT(5) CONSTRAINT PKEmpTable PRIMARY KEY,
EmpName TEXT(30),
EmpSalary CURRENCY
);
// insert some data
INSERT INTO EmpTable VALUES
('E001',
'Anderson, Shannon',
'35000'
);
INSERT INTO EmpTable VALUES
('E002',
'Billings, Jesse',
'30000'
);
INSERT INTO EmpTable VALUES
('E003',
'Caldwell, Dana',
'25000'
);
// show first result set
SELECT * FROM EmpTable AS FirstPass;
// now perform updates
UPDATE EmpTable SET EmpSalary = EmpSalary * 1.10
WHERE EmpSalary > 30000;
UPDATE empTable SET EmpSalary = EmpSalary * 1.15
WHERE EmpSalary <= 30000;
// show new results
SELECT * FROM EmpTable AS SecondPass;
// eof |
|
|
|
|
|
|
|
|
In Listing 15.7, you use the WHERE clause to isolate the records you want to modify with the UPDATE_SET statement. The WHERE clause can be as simple or as complicated as needed to meet the criteria. In other words, any WHERE clause that is valid within the SELECT_FROM statement can be used as part of the UPDATE_SET statement. |
|
|
|
|
|